package com.zhiyou100.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhiyou100.model.Course;
import com.zhiyou100.model.Speaker;
import com.zhiyou100.model.Subject;
import com.zhiyou100.model.Video;
import com.zhiyou100.service.CourseService;
import com.zhiyou100.service.SpeakerService;
import com.zhiyou100.service.SubjectService;
import com.zhiyou100.service.VideoService;

@Controller
@RequestMapping("/user/video")
public class VideoController {
	@Autowired
	private SubjectService ss;
	@Autowired
	private VideoService vs;
	@Autowired
	private SpeakerService sps;
	@Autowired
	private CourseService cs;
	@RequestMapping("index.do")
	public String showDetail(Integer videoId,Integer subjectId,HttpSession session) {
		Subject subject = ss.selectSubject(subjectId);
		Video video = vs.selectVideoOnly(videoId);
		Integer i = video.getVideo_play_times();
		Video v = new Video();
		v.setId(videoId);
		v.setVideo_play_times(i+1);
		vs.updateVideo_play_times(v);
		session.setAttribute("subject", subject);
		session.setAttribute("videoId", videoId);
		return "video/index";
	}
	@RequestMapping("videoData.do")
	public String showVideo(Integer videoId,HttpSession session) {
		Video video = vs.selectVideo(videoId);
		List<Video> video_list = vs.selectVideoAll();
		
		
		session.setAttribute("video", video);
		
		session.setAttribute("video_list", video_list);
		
		return "video/content";
	}
}
